#include <stdio.h>
char* strrepl(const char *oldstr, const char *replstr, const char *str)
{
 // char str[] ="This is a simple string";
  char* newstr = (char*) calloc(strlen(str)+strlen(replstr), sizeof(char));
  char* currstr;
  //char replstr[] = "very simple";
  //char oldstr[] = "simple";
  char* pch;
  size_t len = strlen(replstr);
  pch = strstr(str,oldstr);
  strncpy(newstr, str, pch-str);
  currstr = newstr+(size_t)(pch-str);
  strncpy(currstr,replstr,len);
  pch += strlen(oldstr);
  currstr += len;
  strncpy(currstr,pch,strlen(pch)+1);
  //puts(newstr);
  return newstr;
}
int main()
{
  char str[] ="This is a simple string";
  char replstr[] = "very simple";
  char oldstr[] = "simple";
  char* newstr = strrepl(oldstr, replstr, str);
  puts(newstr);
  return 0;
}
